/* ========================================================================== */
/*   IRSensor.h    		                                                      */
/*   (c) 2012 Team 7 Hogeschool Utrecht ICT TI                                */
/*		Lars Stolwijk, Gerben Boot, Guido van Hienen, Marcel Boelen			  */
/*                                                                            */
/*   Listens to the IR signal. When a usefull command is received the 		  */
/*		IRSensor looks what he can do with it and subsequently activates 	  */
/*		the next task.														  */
/* ========================================================================== */

#ifndef __IRSensor
#define __IRSensor

#define pauseMessures 6

#define irStartStopValue 0
#define irReadLogValue 0b100000
#define signalLength 15
#define pauseBits 4

#include "pRTOS.h"
#include "armboard.h"
#include "IRHitEvent.h"

#include "ReadLogHandler.h"
#include "ProcessHitController.h"
#include "OperationController.h"

class ReadLogHandler;
class ProcessHitController;
class OperationController;

class IRSensor : public RTOS::task {
	public:	
		//Constructor
		IRSensor(int prio,
			ReadLogHandler * readLogHandler, 
			ProcessHitController * processHitController, 
			OperationController * operationController);

	private:	
		enum State { WAITING, RUNNING };
		State CurrentState;

		RTOS::timer IRSTTimer;
		RTOS::clock IRSTClock;

		ReadLogHandler * theReadLogHandler;
		ProcessHitController * theProcessHitController;
		OperationController * theOperationController;

		bool signal;
		char irBits;
		short signalBits;
		char receivedSignalBitsCount;
		char pauseCount;
		
		void main(void);
		void SetIRPause(void);
		void ReadIRValue(void);
		bool CheckIRValue(void);
};

#endif